﻿using System.Web.Mvc;
using Mvc.Validation;
using ValidationSample.Models;

namespace ValidationSample.Controllers
{
    [HandleError]
    public class HomeController : Controller
    {
        [AcceptVerbs(HttpVerbs.Get)]
        public ActionResult EditUser()
        {
            ViewData["Title"] = "Edit User";
            return View();
        }

        [AcceptVerbs(HttpVerbs.Post)]
        public ActionResult EditUser(User user)
        {
            ViewData["Title"] = "Edit User";
            try
            {
                user.Validate();
            }
            catch (EntityValidationException ex)
            {
                ViewData.ModelState.PopulateWithErrors(ex);
            }
            return View();
        }
    }
}
